﻿using System;
using System.Text;
using System.Web.Script.Serialization;

namespace TidyBlog.Util
{
    /// <summary>
    /// JSON工具类
    /// </summary>
    public abstract class JSONHelper
    {
        private static JavaScriptSerializer JSONSerializer = new JavaScriptSerializer();

        static JSONHelper()
        {

        }

        /// <summary>
        /// JSON序列化
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <returns>JSON字符串</returns>
        public static string Serialize(object obj)
        {
            return JSONSerializer.Serialize(obj);
        }

        /// <summary>
        /// JSON序列化并把结果写入到指定的StringBuilder对象
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <param name="output">目标StringBuilder对象</param>
        public static void Serialize(object obj, StringBuilder output)
        {
            JSONSerializer.Serialize(obj, output);
        }
    }
}
